﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lottery.Control {
    public partial class DataLimit : UserControl {
        public DataLimit() {
            InitializeComponent();
        }

        public void SetData(int mediaCount, int combineUp) {
            editA.Text = mediaCount.ToString();
            editB.Text = combineUp.ToString();
            comboBoxLow.Items.Clear();
            comboBoxUp.Items.Clear();
            for (int i = 0; i <= combineUp; i++) {
                comboBoxLow.Items.Add(i);
                comboBoxUp.Items.Add(i);
            }

            comboBoxLow.SelectedIndex = 0;
            comboBoxLow.JumpToNext = comboBoxUp;
            comboBoxUp.SelectedIndex = combineUp;
        }

        public void SetData(int mediaCount, int combineUp, int lowSelected, int upSelected,
            bool isAttended) {
            SetData(mediaCount, combineUp);
            comboBoxLow.SelectedIndex = comboBoxLow.Items.IndexOf(lowSelected);
            comboBoxUp.SelectedIndex = comboBoxUp.Items.IndexOf(upSelected);
            checkBoxAttend.Checked = isAttended;
        }

        /// <summary>
        /// 媒体数
        /// </summary>
        public int MediaCount {
            get { return editA.Value; }
        }

        /// <summary>
        /// 合并数上限
        /// </summary>
        public int CombineUp {
            get { return editB.Value; }
        }

        public int Count {
            get {
                return editB.Value;
            }
        }

        /// <summary>
        /// 当前选中的下限
        /// </summary>
        public int Low {
            get {
                return Convert.ToInt16(comboBoxLow.Text);
            }
        }

        /// <summary>
        /// 当前选中的上限
        /// </summary>
        public int Up {
            get {
                return Convert.ToInt16(comboBoxUp.Text);
            }
        }

        /// <summary>
        /// 是否参与合并数1、2、3的合并，true：参与
        /// </summary>
        public bool Attended { 
            get { return checkBoxAttend.Checked; }
            set { checkBoxAttend.Checked = value; }
        }

        private System.Windows.Forms.Control jumpToNext;
        /// <summary>
        /// 按回车键的时候，焦点跳转到的控件
        /// </summary>
        public System.Windows.Forms.Control JumpToNext {
            get { return jumpToNext; }
            set {
                jumpToNext = value;
                comboBoxUp.JumpToNext = value;
            }
        }


        public bool IsOK {
            get { return Low <= Up; }
        }

        private void CheckData() {
            try {
                if (!IsOK) {
                    labelInfo.ForeColor = Color.Red;
                } else {
                    labelInfo.ForeColor = Color.Black;
                }
            } catch { }
        }

        private void comboBoxLow_SelectedIndexChanged(object sender, EventArgs e) {
            CheckData();
        }

        private void comboBoxUp_SelectedIndexChanged(object sender, EventArgs e) {
            CheckData();
        }
    }
}
